import Vue from 'vue'
import Router from 'vue-router'

Vue.use(Router)

/* Layout */
import Layout from '@/layout'

export const constantRoutes = [
  {
    path: '/login',
    component: () => import('@/views/login/index'),
    hidden: true
  },
  {
    path: '/resgier-student',
    component: () => import('@/views/login/resgier'),
    hidden: true
  },
  {
    path: '/login-teacher',
    component: () => import('@/views/login/teacher'),
    hidden: true
  },
  {
    path: '/login-student',
    component: () => import('@/views/login/student'),
    hidden: true
  },
  {
    path: '/404',
    component: () => import('@/views/404'),
    hidden: true
  },

  {
    path: '/',
    component: Layout,
    redirect: '/dashboard',
    children: [
      {
        path: 'dashboard',
        name: 'Dashboard',
        component: () => import('@/views/dashboard/index'),
        meta: { title: '首页', icon: 'dashboard' }
      }
    ]
  },
  {
    path: '/notice',
    component: Layout,
    redirect: '/notice',
    children: [
      {
        path: 'index',
        name: 'notice',
        component: () => import('@/views/dashboard/notice/notice'),
        meta: { title: '公告管理', icon: 'dashboard' }
      }
    ]
  },
  {
    path: '/calendar',
    component: Layout,
    redirect: '/calendar',
    children: [
      {
        path: 'index',
        name: 'calendar',
        component: () => import('@/views/dashboard/calendar/calendar'),
        meta: { title: '校历管理', icon: 'dashboard' }
      }
    ]
  },
  {
    path: '/exam',
    component: Layout,
    redirect: '/exam',
    children: [
      {
        path: 'index',
        name: 'exam',
        component: () => import('@/views/dashboard/exam/exam'),
        meta: { title: '考试安排', icon: 'dashboard' }
      }
    ]
  },
  {
    path: '/dict',
    component: Layout,
    redirect: '/dashboard',
    meta: { title: '教务管理', icon: 'dashboard' },
    children: [
      {
        path: 'school',
        name: 'school',
        component: () => import('@/views/dict/school/index'),
        meta: { title: '院系', icon: 'dashboard' }
      },
      {
        path: 'class',
        name: 'class',
        component: () => import('@/views/dict/class/index'),
        meta: { title: '班级', icon: 'dashboard' }
      },
      {
        path: 'course-category',
        name: 'course-category',
        component: () => import('@/views/dict/course-category/index'),
        meta: { title: '课程分类', icon: 'dashboard' }
      },
      {
        path: 'course',
        name: 'course',
        component: () => import('@/views/dict/course/index'),
        meta: { title: '课程', icon: 'dashboard' }
      },
      {
        path: 'course-start',
        name: 'course-start',
        component: () => import('@/views/dict/course-start'),
        meta: { title: '开课安排', icon: 'dashboard' }
      }
    ]
  },
  {
    path: '/teacher',
    component: Layout,
    redirect: '/teacher',
    meta: { title: '教师个人中心', icon: 'dashboard' },
    children: [
      {
        path: 'teacher-course',
        name: 'teacher-course',
        component: () => import('@/views/teacher/teacher-course/index'),
        meta: { title: '我的授课', icon: 'dashboard' }
      },
      {
        path: 'student-score',
        name: 'student-score',
        component: () => import('@/views/teacher/student-score/index'),
        meta: { title: '成绩录入', icon: 'dashboard' }
      },
      {
        path: 'student-score-rank',
        name: 'student-score-rank',
        component: () => import('@/views/teacher/student-score-rank/index'),
        meta: { title: '成绩排名', icon: 'dashboard' }
      },
      {
        path: 'student-score-chart',
        name: 'student-score-chart',
        component: () => import('@/views/teacher/student-score-chart/index'),
        meta: { title: '成绩分析', icon: 'dashboard' }
      },
      {
        path: 'course-ap',
        name: 'course-ap',
        component: () => import('@/views/teacher/course-ap/index'),
        meta: { title: '我的课程评价', icon: 'dashboard' }
      },
      {
        path: 'student-day',
        name: 'student-day',
        component: () => import('@/views/teacher/student-day/index'),
        meta: { title: '学生考勤', icon: 'dashboard' }
      }
    ]
  },
  {
    path: '/student',
    component: Layout,
    redirect: '/student',
    meta: { title: '学生个人中心', icon: 'dashboard' },
    children: [
      {
        path: 'choose-course',
        name: 'choose-course',
        component: () => import('@/views/student/choose-course/index'),
        meta: { title: '选课', icon: 'dashboard' }
      },
      {
        path: 'course',
        name: 'course',
        component: () => import('@/views/student/student-course/index'),
        meta: { title: '我的课程', icon: 'dashboard' }
      },
      {
        path: 'score',
        name: 'studentScore',
        component: () => import('@/views/student/score/index'),
        meta: { title: '我的成绩', icon: 'dashboard' }
      },
      {
        path: 'course-ap',
        name: 'course-ap',
        component: () => import('@/views/teacher/course-ap/index'),
        meta: { title: '我的课程评价', icon: 'dashboard' }
      }
    ]
  },
  {
    path: '/student-info',
    name: 'student-info',
    component: () => import('@/views/student/student-info/index'),
    meta: { title: '学生个人信息', icon: 'dashboard' },
    hidden: true
  },
  {
    path: '/teacher-info',
    name: 'teacher-info',
    component: () => import('@/views/teacher/teacher-info/index'),
    meta: { title: '教师个人信息', icon: 'dashboard' },
    hidden: true
  },
  {
    path: '/system',
    component: Layout,
    redirect: '/system',
    meta: { title: '人员管理', icon: 'dashboard' },
    children: [
      {
        path: 'teacher',
        name: 'teacher',
        component: () => import('@/views/system/teacher/index'),
        meta: { title: '教师列表', icon: '' }
      },
      {
        path: 'student',
        name: 'student',
        component: () => import('@/views/system/student/index'),
        meta: { title: '学生列表', icon: '' }
      }
    ]
  },
  // 404 page must be placed at the end !!!
  { path: '*', redirect: '/404', hidden: true }
]

const createRouter = () => new Router({
  // mode: 'history', // require service support
  scrollBehavior: () => ({ y: 0 }),
  routes: constantRoutes
})

const router = createRouter()

// Detail see: https://github.com/vuejs/vue-router/issues/1234#issuecomment-357941465
export function resetRouter() {
  const newRouter = createRouter()
  router.matcher = newRouter.matcher // reset router
}

export default router
